package cn.bingo.yunsj.controller;

import cn.bingo.yunsj.common.exception.EmException;
import cn.bingo.yunsj.common.exception.OwnException;
import cn.bingo.yunsj.common.result.Response;
import cn.bingo.yunsj.controller.model.SerachModel;
import cn.bingo.yunsj.mail.model.MailModel;
import cn.bingo.yunsj.service.FailService;
import cn.bingo.yunsj.service.NotSendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.mail.MessagingException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.io.IOException;

@Api("发送未发送信息")
@Controller
@RequestMapping("/nosend")
@CrossOrigin
public class NotSendController {

    @Autowired
    private NotSendService notSendService;

    @RequestMapping(value = "/all",method = RequestMethod.GET)
    @ApiOperation("搜索所有未发送")
    @ResponseBody
    public Response all(){
        return notSendService.all();
    }

    @RequestMapping(value = "/name",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("获取未发送里面得所有模板种类")
    public Response getName(){
        return notSendService.getName();
    }


    @RequestMapping(value = "/search",method = RequestMethod.GET)
    @ApiOperation("根据未发送人进行搜索")
    @ResponseBody
    public Response search(SerachModel serachModel){
        if(serachModel==null){
            throw new OwnException(EmException.PARAM_EXCPTION);
        }
        String start = "";
        if(serachModel.getStartTime()!=null) {
            start = serachModel.getStartTime().substring(0, serachModel.getStartTime().indexOf("T"));
        }
        String end = "";
        if(serachModel.getEndTime()!=null) {
            end = serachModel.getEndTime().substring(0, serachModel.getEndTime().indexOf("T"));
        }

        // 对后台数据库进行模糊搜索
        return notSendService.search(serachModel, start, end);
    }
}
